from rest_framework import serializers

from goods.models import SPU, SpecificationOption, SPUSpecification


class SPUSimpleSerializer(serializers.ModelSerializer):
    """SPU序列化器类"""
    class Meta:
        model = SPU
        fields = ('id','name')

class SpecOptionSerializer(serializers.ModelSerializer):
    """选项序列化器类"""
    class Meta:
        model = SpecificationOption
        fields = ('id','value')


class SPUSpecSerialzier(serializers.ModelSerializer):
    """SPU序列化器类"""
    #关联对象嵌套序列化
    options = SpecOptionSerializer(label='opt选项',many=True)

    class Meta:
        model = SPUSpecification
        fields = ('id','name','options')















